<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>sessionStorage</title>
</head>
<body>
    <!-- 关闭浏览器数据会消失 -->
    <button onclick="addItem()">点击添加或着修改</button>
    <button onclick="getItem()">根据key获取到存储的数据</button>
    <button onclick="deleteItem()">根据Key删除数据</button>
    <button onclick="clearItem()">清除数据</button>
</body>
<script>
    const arr = [
        {name:'软罗兰',age:24},
        {name:'丁啸山',age:23}
    ]
    function addItem(){
        sessionStorage.setItem('arr',JSON.stringify(arr))
    }
    function getItem(){
        console.log(JSON.parse(sessionStorage.getItem('arr')))
    }
    function deleteItem(){
        sessionStorage.removeItem('arr')
    }
    function clearItem(){
        sessionStorage.clear();
    }
</script>
</html>